//
//  AppDelegate.m
//  音悦咖
//
//  Created by dllo on 15/7/13.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "UMSocial.h"
#import "PlayViewController.h"
#import "L_Singleton.h"
#import "L_footPlaytabBar.h"
#import <AVFoundation/AVFoundation.h>
@interface AppDelegate ()

@property (nonatomic,retain) UIView *firstView;

@end

@implementation AppDelegate


- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 开机动画延迟时间
    [NSThread sleepForTimeInterval:0];
    
#pragma mark 状态栏颜色
    [[UIApplication sharedApplication] setStatusBarStyle:(UIStatusBarStyleLightContent)];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
 
    // 动画执行
         [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAutoreverse animations:^{
            self.firstView = [[UIView alloc] initWithFrame:self.window.bounds];
            self.firstView.backgroundColor = [UIColor clearColor];
            [self.window addSubview:self.firstView];
             [self.firstView release];
    
            UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.firstView.frame];
            NSString *str = [NSString stringWithFormat:@"img%d.jpg",arc4random() % 21];
            imgView.image = [UIImage imageNamed:str];
            [self.firstView addSubview:imgView];
             [imgView release];
    
       
            UILabel *titLable = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.32, SCREEN_HEIGHT * 0.375, 150, 100)];
            titLable.text = @"音悦咖";
            titLable.textColor = [UIColor whiteColor];
            titLable.font = [UIFont fontWithName:@"Helvetica-Bold" size:40];
            [imgView addSubview:titLable];
             [titLable release];
            
             
        } completion:^(BOOL finished) {


    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:(UIStatusBarAnimationFade)];
    
    MainViewController *main = [[MainViewController alloc] init];
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:main];

    
    L_footPlaytabBar *footPlayTabBar = [L_footPlaytabBar shareTabBar];
    footPlayTabBar.viewControllers = @[navi];
 
    self.window.rootViewController = footPlayTabBar;
    
    // 友盟连接
    [UMSocialData setAppKey:@"55aa363567e58ebf5300291b"];


    
#pragma mark   后台播放

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:nil];
      
    [main release];
    [navi release];
    
    [_window release];
        
        }];

    return YES;
}
// 禁止屏幕翻转
-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortrait;
}

    


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
     [application beginBackgroundTaskWithExpirationHandler:nil];
    
    //开启一个后台标示任务
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    
       // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
